<template>
	<view>
		<TabMenu :menus="tabList" :tabCur="tabCur" ref="tableMenu" @clickCtTab="clickCtTab"></TabMenu>
		<view class="total-info">订单记账总额：￥{{amount}}，订单数量: {{count}}</view>
		<view>
			<template v-if="orders.length>0">
				<OrderAll :order="item" v-for="(item,index) in orders" :key="item.id"></OrderAll>
			</template>
			<Nodata v-else></Nodata>
		</view>
	</view>
</template>

<script>
	import TabMenu from '@/components/TabMenu.vue'
	import Nodata from '@/components/Nodata.vue'
	import OrderAll from '@/components/OrderAll.vue'
	import {
		getOrders
	} from '@/request/api/resultOrder.js'
	export default {
		components: {
			TabMenu,
			OrderAll,
			Nodata
		},
		activated() {
			this.tabCur = uni.getStorageSync('abc') // 输出 'value1'
			this.$refs.tableMenu.clickCtTab(this.tabCur)
		},
		mounted() {
			this.tabCur = uni.getStorageSync('abc') // 输出 'value1'
			this.$refs.tableMenu.clickCtTab(this.tabCur)
		},
		onHide() {
			uni.setStorageSync('abc', 0)
		},
		data() {
			return {
				tabCur: 0,
				tabList: [{
					title: '全部',
				}, {
					title: '待付款',
				}, {
					title: '待收款',
				}, {
					title: '待收货',
				}, {
					title: '已出售'
				}],
				amount: '0',
				count: 0,
				orders: [],
			}
		},
		methods: {
			clickCtTab(ctCur) {
				this.tabCur = ctCur
				this.getOrders(this.tabCur)
			},
			async getOrders(state) {
				const res = await getOrders(state - 1)
				if (res.data.list) {
					this.orders = res.data.list
					this.amount = res.data.amount
					this.count = res.data.count
				}
			}
		}
	}
</script>

<style>
	.total-info {
		width: 100%;
		background-image: linear-gradient(90deg, #2c7fd9, #2c7fd9);
		font-size: 15px;
		font-weight: 500;
		color: #fff;
		line-height: 30px;
		padding: 0 10px;
	}
</style>